package 接力赛跑;

public class RunThread implements Runnable{
    private static int count=1000;


    public synchronized static void show (){
        if (count>0){
            System.out.println(Thread.currentThread().getName()+"拿到接力棒");
            for (int i = 1; i <=10 ; i++) {
                System.out.println(Thread.currentThread().getName()+"跑了"+(10*i)+"米");
            }
        }
    }

    @Override
    public void run() {
        while (true) {
            if (count==0){
                System.out.println("已经到终点了");
                break;
            }
            show();
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            count-=100;
           return;
        }
    }

    public static void main(String[] args) {

       RunThread r = new RunThread();
        for (int i = 1; i <=10 ; i++) {
            Thread t =new Thread(r,i+"号选手");
            t.start();
        }

    }
}
